const express = require('express')
const cors = require('cors')
const fs = require('fs')

const app = express()
const port = 3000

// 解决跨域问题
app.use(cors())

// 读取 data.json 文件
const dataFilePath = './data.json'
const qnaData = JSON.parse(fs.readFileSync(dataFilePath, 'utf-8'))

// 获取所有问题和答案的路由
app.get('/api/qna', (req, res) => {
  res.json(qnaData)
})

// 启动服务器
app.listen(port, () => {
  console.log(`Server is running on http://localhost:${port}`)
})
